package com.emep.changzhi.analyse.http.datamonitor;

import com.emep.changzhi.analyse.entity.datamonitor.DataDroppedRecord;
import com.emep.changzhi.analyse.model.ResultBean;
import com.emep.changzhi.analyse.service.datamonitor.DataDroppedRecordService;
import com.emep.changzhi.analyse.utils.Constant;
import com.emep.changzhi.analyse.utils.DataValidator;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author yangj
 * @version V1.0
 * @Description: DOTO
 * @date 2018/2/26  16:56
 */
@RestController
@RequestMapping("dataDroppedRecord")
@Api(value="掉线记录controller",tags={"掉线记录操作接口"})
public class DataDroppedRecordController {

    @Autowired
    private DataDroppedRecordService dataDroppedRecordService;

    /**
     * 新增掉线记录
     * @return
     * */
    @ApiOperation(value = "新增掉线记录" , notes = "新增掉线记录")
    @ApiResponses({
            @ApiResponse(code = 1,message = "操作成功"),
            @ApiResponse(code = 0,message = "操作失败，服务器内部异常"),
            @ApiResponse(code = 303,message = "权限不足")})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mn", value = "设备mn号", required = true, dataType = "String",paramType="query"),
            @ApiImplicitParam(name = "run_status", value = "设备状态", required = true, dataType = "String",paramType="query"),
            @ApiImplicitParam(name = "start_time", value = "时间", required = true, dataType = "String",paramType="query"),
    })
    @PostMapping(value = "add")
    public ResultBean<DataDroppedRecord> add(@RequestParam Map<String , Object> payload){
        ResultBean result = DataValidator.validateMapData(payload, "mn","runStatus","startTime");
        if(result.getCode() == 1){
            return result.boolAdd(dataDroppedRecordService.saveDataDroppedRecord(payload));
        }
        return  result;
    }

    /**
     * @author xy
     * @Description: 首页
     * @date 2018/3/8 11:49
     * @version V1.0
     */
    @ApiOperation(value="首页", notes="首页")
    @ApiResponses({ @ApiResponse(code = 1, message = "操作成功"),
            @ApiResponse(code = 0, message = "操作失败，服务器内部异常"),
            @ApiResponse(code = 303, message = "权限不足") })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageSize", value = "查询数量", required = true, dataType = "String",paramType="query")
    })
    @GetMapping(value = "home")
    public List<DataDroppedRecord> findDataDroppedRecordByHome(@RequestParam Map<String, Object> payload){
        ResultBean result = DataValidator.validateMapData(payload, "pageSize");
        if (result.getCode() == Constant.RESULT_CODE_SUCCESS) {
            return dataDroppedRecordService.findDataDroppedRecordByHome(Integer.parseInt(payload.get("pageSize").toString()));
        }
        return  null;
    }
    /**
     * @author xy
     * @Description: 翻页查询
     * @date 2018/3/8 11:49
     * @version V1.0
     */
    @ApiOperation(value="翻页查询", notes="翻页查询")
    @ApiResponses({ @ApiResponse(code = 1, message = "操作成功"),
            @ApiResponse(code = 0, message = "操作失败，服务器内部异常"),
            @ApiResponse(code = 303, message = "权限不足") })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "查询起始id", required = true, dataType = "String",paramType="query"),
            @ApiImplicitParam(name = "pageSize", value = "查询数量", required = true, dataType = "Integer",paramType="query")
    })
    @GetMapping(value = "flip")
    public List<DataDroppedRecord> findDataDroppedRecordByFlip(@RequestParam Map<String, Object> payload){
        ResultBean result = DataValidator.validateMapData(payload, "id","pageSize");
        if (result.getCode() == Constant.RESULT_CODE_SUCCESS){
            return dataDroppedRecordService.findDataDroppedRecordByFlip(payload.get("id").toString() , Integer.parseInt(payload.get("pageSize").toString()));
        }
        return null;
    }


}
